﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Sword.Data
{
    [Serializable]
    public class ConditionItem
    {
        public bool pass;
        public bool block;

        /// <summary>
        /// 数据（or条件）类型
        /// </summary>
        [XmlAttribute("ConditionType")]
        public ConditionEnumType ConditionType { get; set; }

        /// <summary>
        /// 【匹配表达式
        /// </summary>
        [XmlAttribute("Expression")]
        public string Expression { get; set; }

        /// <summary>
        /// 匹配结果
        /// </summary>
        //[XmlAttribute("Result")]
        [XmlIgnore]
        public string Result { get; set; }

        /// <summary>
        /// 匹配结果(Clean)
        /// </summary>
        [XmlAttribute("ActualResult")]
        public string ActualResult { get; set; }

        /// <summary>
        /// 匹配结果类型
        /// </summary>
        [XmlAttribute("ResultType")]
        public ResultEnumType ResultType { get; set; }

    }

    public enum ResultEnumType
    {
        /// <summary>
        /// 未指定
        /// </summary>
        None = 0,
        /// <summary>
        /// 修改主机
        /// </summary>
        Host = 1,
        /// <summary>
        /// 修改指向IP
        /// </summary>
        IP = 2,
        /// <summary>
        /// 修改Url
        /// </summary>
        Url = 3,
        /// <summary>
        /// 指定返回数据
        /// </summary>
        Data = 4,
        /// <summary>
        /// 指定返回http code
        /// </summary>
        Code = 5,
        /// <summary>
        /// 指定返回数据
        /// </summary>
        ConditionGroup = 6,
    }

    public enum ConditionEnumType
    {
        /// <summary>
        /// 未指定
        /// </summary>
        None = 0,
        /// <summary>
        /// 主机匹配
        /// </summary>
        Host = 1,
        /// <summary>
        /// 主机匹配(+正则)
        /// </summary>
        HostWithRegexExpression = 2,
        /// <summary>
        /// Url匹配
        /// </summary>
        Url = 3,
        /// <summary>
        /// Url匹配(+正则)
        /// </summary>
        UrlWithRegexExpression = 4,
        /// <summary>
        /// Url匹配
        /// </summary>
        ShortHost = 5,
        /// <summary>
        /// 请求的Header 内容值匹配
        /// </summary>
        RequestHeader = 6,
        /// <summary>
        /// 让请求走远程代理(翻墙等用途)
        /// </summary>
        HttpProxy = 98,
        /// <summary>
        /// 注释
        /// </summary>
        Comment = 99,
    }
}
